package store;

/**
 * 策略上下文环境
 *
 * @author jiang
 * @date 2021/10/30
 */
public class StoreContext {

    /**
     * 默认价格更新策略
     */
    private static final StoreStrategy DEFAULT_STORE_STRATEGY = new StoreStrategyDefault();

    /**
     * 陈年老酒（Aged Wine）
     */
    private static final String STRATEGY_AGED_WINE = "Aged Wine";

    /**
     * （Sulfuras）
     */
    private static final String STRATEGY_SULFURAS = "Sulfuras";

    /**
     * 演出票（Show Ticket）
     */
    private static final String STRATEGY_SHOW_TICKET = "Show Ticket";

    /**
     * 特效药（Cure）
     */
    private static final String STRATEGY_CURE = "Cure";


    StoreStrategy storeItemService;

    public StoreContext(String itemName) {
        if (itemName == null) {
            storeItemService = DEFAULT_STORE_STRATEGY;
            return;
        }
        switch (itemName) {
            case STRATEGY_AGED_WINE:
                storeItemService = new StoreStrategyAgedWine();
                break;
            case STRATEGY_SULFURAS:
                storeItemService = new StoreStrategySulfuras();
                break;
            case STRATEGY_SHOW_TICKET:
                storeItemService = new StoreStrategyShowTicket();
                break;
            case STRATEGY_CURE:
                storeItemService = new StoreStrategyCure();
                break;
            default:
                storeItemService = DEFAULT_STORE_STRATEGY;
                break;
        }
    }


    /**
     * 更新策略执行
     *
     * @param item
     */
    public void updateValue(Item item) {
        storeItemService.updateSellIn(item);
        storeItemService.updateValue(item);
    }

}
